package org.duncan.sjge.gamedata.sprites;

import java.io.File;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;

/**
 *
 * @author Duncan
 */
public class SpriteMgr {
    private Map<File, Sprite> mSprites = new HashMap<>();
    
    public Sprite get(final File file) {
        if (!mSprites.containsKey(file)) {
            System.out.println("Loading image '" + file.getName() + "'.");
            try {
                mSprites.put(file, new Sprite(file));
            } catch (final IOException ex) {
                System.err.println("Error! Could not find image file '" + file + "'.");
                ex.printStackTrace();
                System.exit(1);
            }
        }
        return mSprites.get(file);
    }
    
    // Singleton
    private static SpriteMgr inst;
    public static SpriteMgr instance() {
        if (inst == null) {inst = new SpriteMgr();}
        return inst;
    }
}
